home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gstrap.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.5 KB  |  110 lines

  1. /* Copyright (C) 1997, 1998, 1999, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gstrap.c,v 1.3 2000/09/19 19:00:33 lpd Exp $ */
  20. /* Setting trapping parameters and zones */
  21. #include "string_.h"
  22. #include "gx.h"
  23. #include "gserrors.h"
  24. #include "gstrap.h"
  25. #include "gsparamx.h"
  26.  
  27. /* Put a float parameter. */
  28. private bool
  29. check_unit(float *pval)
  30. {
  31.     return (*pval >= 0 && *pval <= 1);
  32. }
  33. private bool
  34. check_positive(float *pval)
  35. {
  36.     return (*pval > 0);
  37. }
  38. private int
  39. trap_put_float_param(gs_param_list * plist, gs_param_name param_name,
  40.              float *pval, bool(*check) (P1(float *pval)), int ecode)
  41. {
  42.     int code;
  43.  
  44.     switch (code = param_read_float(plist, param_name, pval)) {
  45.     case 0:
  46.         if ((*check) (pval))
  47.         return 0;
  48.         code = gs_error_rangecheck;
  49.     default:
  50.         ecode = code;
  51.         param_signal_error(plist, param_name, ecode);
  52.         break;
  53.     case 1:
  54.         break;
  55.     }
  56.     return ecode;
  57. }
  58.  
  59. /* settrapparams */
  60. int
  61. gs_settrapparams(gs_trap_params_t * pparams, gs_param_list * plist)
  62. {
  63.     gs_trap_params_t params;
  64.     int ecode = 0;
  65.     static const char *const trap_placement_names[] = {
  66.     gs_trap_placement_names, 0
  67.     };
  68.  
  69.     params = *pparams;
  70.     ecode = trap_put_float_param(plist, "BlackColorLimit",
  71.                  ¶ms.BlackColorLimit, check_unit, ecode);
  72.     ecode = trap_put_float_param(plist, "BlackDensityLimit",
  73.                  ¶ms.BlackDensityLimit,
  74.                  check_positive, ecode);
  75.     ecode = trap_put_float_param(plist, "BlackWidth",
  76.                  ¶ms.BlackWidth, check_positive, ecode);
  77.     ecode = param_put_bool(plist, "Enabled",
  78.                ¶ms.Enabled, ecode);
  79.     ecode = param_put_bool(plist, "ImageInternalTrapping",
  80.                ¶ms.ImageInternalTrapping, ecode);
  81.     ecode = param_put_bool(plist, "ImagemaskTrapping",
  82.                ¶ms.ImagemaskTrapping, ecode);
  83.     ecode = param_put_int(plist, "ImageResolution",
  84.               ¶ms.ImageResolution, ecode);
  85.     if (params.ImageResolution <= 0)
  86.     param_signal_error(plist, "ImageResolution",
  87.                ecode = gs_error_rangecheck);
  88.     ecode = param_put_bool(plist, "ImageToObjectTrapping",
  89.                ¶ms.ImageToObjectTrapping, ecode);
  90.     {
  91.     int placement = params.ImageTrapPlacement;
  92.  
  93.     ecode = param_put_enum(plist, "ImageTrapPlacement",
  94.                    &placement, trap_placement_names, ecode);
  95.     params.ImageTrapPlacement = placement;
  96.     }
  97.     ecode = trap_put_float_param(plist, "SlidingTrapLimit",
  98.                  ¶ms.SlidingTrapLimit, check_unit, ecode);
  99.     ecode = trap_put_float_param(plist, "StepLimit",
  100.                  ¶ms.StepLimit, check_unit, ecode);
  101.     ecode = trap_put_float_param(plist, "TrapColorScaling",
  102.                  ¶ms.TrapColorScaling, check_unit, ecode);
  103.     ecode = trap_put_float_param(plist, "TrapWidth",
  104.                  ¶ms.TrapWidth, check_positive, ecode);
  105.     if (ecode < 0)
  106.     return ecode;
  107.     *pparams = params;
  108.     return 0;
  109. }
  110.